package com.itheima.wechat;

import com.itheima.constant.RedisConstant;
import com.itheima.entity.Result;
import com.itheima.utils.JedisUtl;
import com.itheima.utils.ValidateCodeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/validateCode")
public class ValidateCodeController {

    //spring 容器就得有这个对象
    //<dubbo:annotation package="com.itheima.om.itheima.wechat,com.itheima.utils"></dubbo:annotation>
    @Autowired
    JedisUtl jedisUtl;


    @RequestMapping("/send4Order")
    public Result send4Order(String telephone){
        Integer code = ValidateCodeUtils.generateValidateCode(4);
//        SmsUtil.sendSmsCode(telephone,code);
        System.out.println("code:" + code);

        jedisUtl.setex(telephone+ RedisConstant.SMS_CODE_KEY_ORDER,60 * 5 * 100,String.valueOf(code));

        return Result.OK("");
    }

    //
    @RequestMapping("/send4Login")
    public Result send4Login(String telephone){
        Integer code = ValidateCodeUtils.generateValidateCode(4);
//        SmsUtil.sendSmsCode(telephone,code);
        System.out.println("code:" + code);

        jedisUtl.setex(telephone+ RedisConstant.SMs_CODE_KEY_LOGIN,60 * 5 * 100,String.valueOf(code));

        return Result.OK("");
    }


}
